package com.gorun.flutter_alipush

import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.graphics.Color
import android.os.Build
import android.util.Log
import com.alibaba.sdk.android.push.CommonCallback
import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory
import com.jarvanmo.rammus.RammusPushIntentService
import io.flutter.app.FlutterApplication


class MyApplication: FlutterApplication() {
    override fun onCreate() {
        super.onCreate()
        PushServiceFactory.init(applicationContext)
        val pushService = PushServiceFactory.getCloudPushService()
        val callback = object : CommonCallback {
            override fun onSuccess(response: String?) {
                Log.e("TAG","success $response")
            }
            override fun onFailed(errorCode: String?, errorMessage: String?) {
                Log.e("TAG","error $errorMessage")
            }
        }
        pushService.register(applicationContext,callback)
        //一定要添加这一句代码
        pushService.setPushIntentService(RammusPushIntentService::class.java)

//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//            val mNotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
//            // 通知渠道的id
//            val id = "10010"
//            // 用户可以看到的通知渠道的名字
//            val name: CharSequence = "notification channel"
//            // 用户可以看到的通知渠道的描述。
//            val description = "notification description"
//            val importance = NotificationManager.IMPORTANCE_HIGH
//            val mChannel = NotificationChannel(id, name, importance)
//            // 配置通知渠道的属性。
//            mChannel.setDescription(description)
//            // 设置通知出现时的闪灯（如果Android设备支持的话）。
//            mChannel.enableLights(true)
//            mChannel.setLightColor(Color.RED)
//            // 设置通知出现时的震动（如果Android设备支持的话）。
//            mChannel.enableVibration(true)
//            mChannel.vibrationPattern = longArrayOf(100, 200, 300, 400, 500, 400, 300, 200, 400)
//            // 最后在notificationmanager中创建该通知渠道。
//            mNotificationManager.createNotificationChannel(mChannel);
//
//        }

    }


}